﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace Winsmarts.CrossSCNav.NavigationWebPart
{
    [ToolboxItemAttribute(false)]
    public class NavigationWebPart : WebPart
    {
        private NavigationWebPartControl control;

        protected override void CreateChildControls()
        {
            EnsureChildControls();
            control = this.Page.LoadControl("~/_controltemplates/Winsmarts.CrossSCNav/Winsmarts.CrossSCNav.ascx") as NavigationWebPartControl;
            control.ID = "NavigationWebPartControl1";
            control.UrlPattern = UrlMatchPattern;
            this.Controls.Add(control);

            ScriptManager scriptManager1 = ScriptManager.GetCurrent(this.Page);
            if (scriptManager1 == null)
            {
                scriptManager1 = new ScriptManager() { ID = "ScriptManager1" };
                this.Controls.Add(scriptManager1);
            }
            scriptManager1.Services.Add(new ServiceReference("~/_vti_bin/Winsmarts.CrossSCNav/endpoint.svc"));

            base.CreateChildControls();
        }

        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        public string UrlMatchPattern { get; set; }
    }
}
